package driver.nxt.events;

import icommand.nxt.LightSensor;
import icommand.nxt.SensorPort;
import driver.events.Event;
import driver.exceptions.SensorException;

/**
 * Provides a mechanism for reading from the NXT Light Sensor
 *
 * @author David Martin
 */
public class NXTLightEvent extends Event
{

  private static final String EVENT_NAME = "Light Sensor";
  private LightSensor sensor;

  /**
   * Assigns the sensor port for the Light Sensor and sets it to passive mode
   */
  public NXTLightEvent()
  {
    super();
    sensor = new LightSensor(SensorPort.S3);
    sensor.passivate();
  }

  public String getEventName()
  {
    return EVENT_NAME;
  }

  /**
   * Gets the latest light reading as a percent, where 0 is no light and 100
   * is maximum brightness
   *
   * @return the light reading as a percentage
   * @throws driversuite.exceptions.SensorException
   */
  public String readFromSensor() throws SensorException
  {
    return String.valueOf(sensor.getLightPercent());
  }

  public String getMeasurementUnits()
  {
    return "%";
  }
}
